import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/home',
    name: 'Home',
    redirect: '/',
    component: Home
  },
  {
    // path: '/tab/:tabid',
    path: '/tab',
    name: 'Tab',
    component: () => import('@/views/Tab.vue'),
    children: [
      {
        path: '/tab/:tabid',
        component: () => import('@/views/Tab/TabBox.vue')
      }
    ]
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/views/Search.vue')
  },
  {
    path: '/category/:categoryid',
    name: 'Category',
    component: () => import('@/views/Category.vue')
  },
  {
    path: '/column/:columnid',
    name: 'Column',
    component: () => import('@/views/Column.vue')
  },
  {
    path: '/result/:sword',
    name: 'searchResult',
    component: () => import('@/views/SearchResult.vue')
  },
  {
    path: '/detail/:id',
    name: 'Detail',
    component: () => import('@/views/Detail.vue')
  },
  {
    path: '/toplist',
    name: 'Toplist',
    component: () => import('@/views/TopList.vue')
  }
]

const router = new VueRouter({
  routes,
  // 路由每次切换的时候scroll都回到顶部
  scrollBehavior (to, from, savedPosition) {
    return {
      x: 0,
      y: 0
    }
  }
})

export default router
